package com.test.controller;

import com.test.entity.Book;
import com.test.service.BookService;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

@RestController
public class BookController {

    @Resource
    private BookService bookService;

    @GetMapping("/book/{bid}")
    public Book findBookById(@PathVariable("bid") int bid) {
        //通过SecurityContextHolder将用户信息取出
        SecurityContext context = SecurityContextHolder.getContext();
        System.out.println(context.getAuthentication());
        return bookService.getBookById(bid);
    }
}
